package com.self.campussecondhandmarket.controller.admin;

import com.self.campussecondhandmarket.entity.request.admin.LoginRequest;
import com.self.campussecondhandmarket.resp.Result;
import com.self.campussecondhandmarket.service.AdminService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: Vincent
 * <p> DateTime: 2024/4/17 14:56
 * <p> Description: 后台管理账号
 * <p>
 **/
@CrossOrigin(origins = "http://localhost:9999", allowCredentials = "true")
@RestController
@RequestMapping("/api/admin")
public class AdminController {
	
	@Autowired
	private AdminService adminService;
	
	@PostMapping("/login")
	public Result<String> login(@RequestBody @NonNull LoginRequest loginRequest) {
		if (loginRequest.getPassword().isEmpty() || loginRequest.getUsername().isEmpty())
			return Result.error("用户名或密码不能为空");
		
		return adminService.login(loginRequest);
	}
	
}
